﻿using MyMes.Infrastructure;
using MyMES.IServices.Holidayes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VOL.Core.Utilities.Response;
using VOL.Entity.DomainModels;

namespace MyMES.Services.Holidayes
{
    public class HolidaysServices:IHolidaysServices
    {
        private readonly IBaseRepository<Holidays> _holidaysbaseRepository;

        public HolidaysServices(IBaseRepository<Holidays> holidaysbaseRepository)
        {
            _holidaysbaseRepository = holidaysbaseRepository;
        }

        public Task<WebResponseContent> GetHolidays()
        {
            var result = new WebResponseContent();
            var HolidaysList = _holidaysbaseRepository.GetAll();
            result.OK("查询节假日成功", HolidaysList);
            return Task.FromResult(result);

        }
        public async Task<WebResponseContent> CreateUpdateHolidays(Holidays holidays)
        {
            var result = new WebResponseContent();
            if (holidays.Id != 0)
            {
                var holidy = _holidaysbaseRepository.GetAll().FirstOrDefault(a => a.Id == holidays.Id);
                holidy.HolidaysTime = holidays.HolidaysTime;
                holidy.HolidaysType = holidays.HolidaysType;
                var entity = await _holidaysbaseRepository.UpdateAsync(holidy);
            }
            else
            {
                var entity = await _holidaysbaseRepository.AddAsync(holidays);
            }

            return result.OK("成功", null);
        }
    }
}
